using System;
using Sinacor.Servico.Bovespa.Ordens.BusinessEntity;
using Sinacor.Servico.Bovespa.Ordens.Service.DataContract.Response;
using System.ComponentModel;
using System.Collections.Generic;

namespace Sinacor.Servico.Bovespa.Ordens.Service.ServiceImplementation.Translator
{
    public static class TranslateBetweenJustificativaAndJustificativaResponse
    {
        public static Sinacor.Servico.Bovespa.Ordens.BusinessEntity.Justificativa TranslateJustificativaResponseToJustificativa(Sinacor.Servico.Bovespa.Ordens.Service.DataContract.Response.JustificativaResponse from)
        {
            Sinacor.Servico.Bovespa.Ordens.BusinessEntity.Justificativa to = new Sinacor.Servico.Bovespa.Ordens.BusinessEntity.Justificativa();
            to.TextoJustificativa = from.Texto;
            to.IdentificadorJustificativa = from.IdentificadorJustificativa;
            to.DataAlteracao = from.DataAlteracao;
            if (to.Ordem == null)
                to.Ordem = new Sinacor.Servico.Bovespa.Ordens.BusinessEntity.Ordem();
            to.Ordem.CodigoCliente = from.CodigoCliente;
            to.Ordem.NumeroOrdem = from.NumeroOrdem; 
            return to;
        }

        public static Sinacor.Servico.Bovespa.Ordens.Service.DataContract.Response.JustificativaResponse TranslateJustificativaToJustificativaResponse(Sinacor.Servico.Bovespa.Ordens.BusinessEntity.Justificativa from)
        {
            Sinacor.Servico.Bovespa.Ordens.Service.DataContract.Response.JustificativaResponse to = new Sinacor.Servico.Bovespa.Ordens.Service.DataContract.Response.JustificativaResponse();
            to.Texto = from.TextoJustificativa;
            to.IdentificadorJustificativa = from.IdentificadorJustificativa;
            to.DataAlteracao = from.DataAlteracao;
            if (from.Ordem == null)
            {
                from.Ordem = new Sinacor.Servico.Bovespa.Ordens.BusinessEntity.Ordem();
            }
            else //incluido else - eduardo sertorio - 200802161734
            {
                to.CodigoCliente = from.Ordem.CodigoCliente.Value;
                to.NumeroOrdem = from.Ordem.NumeroOrdem.Value;
            }
            return to;
        }

        public static List<DataContract.Response.JustificativaResponse>
            TranslateJustificativaCollectionJustificativaResponseCollection(List<BusinessEntity.Justificativa> from)
        {
            List<DataContract.Response.JustificativaResponse> to = null;

            if (from != null)
            {
                to = new List<DataContract.Response.JustificativaResponse>();
                foreach (BusinessEntity.Justificativa listaJustificativa in from)
                {
                    to.Add(TranslateBetweenJustificativaAndJustificativaResponse.
                        TranslateJustificativaToJustificativaResponse(listaJustificativa));
                }
            }

            return to;
        }
    }
}

